package com.zhiwang.planet.ui.loginv2

import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProviders
import com.zhiwang.planet.R
import com.zhiwang.planet.databinding.ActivityRegisterV2Binding
import com.zhiwang.planet.di.component.DaggerUserComponent
import com.zhiwang.planet.di.module.AccountModule
import com.zhiwang.planet.di.module.AutoDisposeModule
import com.zhiwang.planet.mvvm.model.RestApi
import com.zhiwang.planet.mvvm.viewmodel.loginv2.RegisterViewModel
import com.zhiwang.planet.mvvm.viewmodel.loginv2.WxLoginViewModel
import com.zhiwang.planet.ui.BaseActivity
import com.zhiwang.planet.util.Utils
import kotlinx.android.synthetic.main.activity_register_v2.*
import javax.inject.Inject

class RegisterV2Activity:BaseActivity() {

    @Inject
    lateinit var restApi: RestApi

    lateinit var viewModel: RegisterViewModel

    var token = ""

    override fun initInjection() {
        super.initInjection()
        DaggerUserComponent.builder()
                .appComponent(getAppComponent())
                .autoDisposeModule(AutoDisposeModule(this))
                .accountModule(AccountModule(this))
                .build()
                .inject(this)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding = DataBindingUtil
                .setContentView<ActivityRegisterV2Binding>(this, R.layout.activity_register_v2)
        setSupportActionBar(toolbar)
        Utils.setStatusBar(this, false, true)
        viewModel = ViewModelProviders.of(this).get(RegisterViewModel::class.java)

        viewModel.context = this
        if (intent.hasExtra("code"))
            viewModel.setCode(intent.getStringExtra("code"))
        if (intent.hasExtra("deviceId"))
            viewModel.setDeviceId(intent.getStringExtra("deviceId"))
        binding.lifecycleOwner = this
        binding.viewModel = viewModel
        viewModel.restApi = restApi
        viewModel.errHandler = ::onError

    }
}